﻿<?php
	if ($_GET['testdbpwd']) 
	{
		$dataresult = '';
		if(empty($_POST['dbName']))
		{
			$dataresult = $dataresult . '1';
		}

		$dbHost = $_POST['dbHost'] . ':' . $_POST['dbPort'];
		$conn = @mysql_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd']);
		if (!$conn) 
		{
			$dataresult = $dataresult . '2';
		}
		
		if(empty($_POST['sysUser']))
		{
			$dataresult = $dataresult . '3';
		}
		
		if(empty($_POST['sysPwd']))
		{
			$dataresult = $dataresult . '4';
		}

		die($dataresult);
	}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>东丘管理系统安装向导</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="./js/jquery.min.js" language="javascript" type="text/javascript"></script>
        <script src="./js/jquery.form.js" language="javascript" type="text/javascript"></script>
        <script src="./js/jquery.validate.js" language="javascript" type="text/javascript"></script>
        <link href="./css/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div class="main">
            <h5>欢迎使用东丘管理系统</h5>

            <div class="title">
				<ul>
                    <?php  foreach($steps as $key=>$res){ ?>
                    <li <?php if($step==$key):?> class="on"<?php endif;?> ><?php echo $res?></li>
                    <?php } ?>
                </ul>
			</div>

            <div class="box">
				<div class="b1">
					<div class="right">

						<h1>数据库安装</h1>

						<form id="myform" action="index.php?step=4" method="post" name="form1">
							<table   border="0" align="center" cellpadding="0" cellspacing="0" class="table">

								<tr>
									<td width="170"><strong>数据库主机：</strong></td>
									<td width="410"><input name="dbHost" type="text" id="dbHost" value="localhost" size="30" />
										<small>(一般为localhost)</small></td>
								</tr>
								<tr>
									<td><strong>数据库端口：</strong></td>
									<td><input name="dbPort" type="text" id="dbPort" value="3306" size="10" /></td>
								</tr>
								<tr>
									<td><strong>数据库名称：</strong></td>
									<td>
										<input name="dbName" type="text" id="dbName" value="dq_trade" size="20"  onblur="TestData()" />
										<span id='dbname_msg'></span>            
									</td>
									</td>
								</tr>
								<tr>
									<td><strong>数据库用户：</strong></td>
									<td><input name="dbUser" type="text" id="dbUser" value="root" size="20" /></td>
								</tr>
								<tr>
									<td><strong>数据库密码：</strong></td>
									<td>
										<input name="dbPwd" type="text" id="dbPwd" size="20"  onblur="TestData()" />
										<span id='dbpwd_msg'></span>            
									</td>
								</tr>
								<tr>
									<td><strong>系统管理员：</strong></td>
									<td><input name="sysUser" type="text" id="sysUser" value="admin" size="20" onblur="TestData()" />
										<span id='sysuser_msg'></span>            
									</td>
								</tr>
								<tr>
									<td><strong>管理员密码：</strong></td>
									<td>
										<input name="sysPwd" type="text" id="sysPwd" size="20"  onblur="TestData()" />
										<span id='syspwd_msg'></span>            
									</td>
								</tr>
								<tr>
									<td><strong>表前缀：</strong></td>
									<td>
										<input name="tbl_pre" type="text" id="tbl_pre" value="dqt_" size="10"/> <small>(默认为 dqt_)</small>         
									</td>
								</tr>
							</table>

							<div class="butbox">
								<input type="button" class="inputButton" value=" 上一步 " onclick="history.back();" style="margin-right:20px" />
								<input name="dosubmit" type="submit" class="inputButton nonext" id="dosubmit" value=" 下一步 " disabled  />
							</div>
						</form>

					</div>
				</div>
				<div class="power">Powered by <a href="#" target="_blank">大连东丘贸易有限公司</a> 
				</div>
			</div>
		</div>
	</body>
	<script language="javascript" type="text/javascript">
		$(document).ready(function(){
			$('#dbName').blur();
			$('#dbPwd').blur();
			$('#sysUser').blur();
			$('#sysPwd').blur();
			$(".table tr").each(function(){ $(this).children("td").eq(0).addClass("on");});
			$("input[type='text']").addClass("input_blur").mouseover(function(){ $(this).addClass("input_focus");}).mouseout(function(){$(this).removeClass("input_focus");});
			$(".table tr").mouseover(function(){ $(this).addClass("mouseover");}).mouseout(function(){$(this).removeClass("mouseover");	});
		});
	 
		$.ajaxSetup ({ cache: false });
		function TestData()
		{
			var dbHost = $('#dbHost').val();
			var dbUser = $('#dbUser').val();
			var dbPwd = $('#dbPwd').val();
			var dbName = $('#dbName').val();
			var dbPort = $('#dbPort').val();
			var sysUser = $('#sysUser').val();
			var sysPwd = $('#sysPwd').val();
			data={'dbHost':dbHost,'dbUser':dbUser,'dbPwd':dbPwd,'dbName':dbName,'dbPort':dbPort,'sysUser':sysUser,'sysPwd':sysPwd};
			var url =  "./index.php?step=3&testdbpwd=1";
			$.ajax({
				type: "POST",
				url: url,
				data: data,
				success: function(msg){
					if(msg.indexOf('1')>=0)
					{
						$('#dosubmit').attr("disabled",true);
						$('#dosubmit').addClass("nonext");
						$('#dbname_msg').css('color','#FB0000').html("数据库名称配置失败");	
					}
					else
					{
						$('#dbname_msg').css('color','#00FB00').html("数据库名称配置正确");	
					}
					if(msg.indexOf('2')>=0)
					{
						$('#dosubmit').attr("disabled",true);
						$('#dosubmit').addClass("nonext");
						$('#dbpwd_msg').css('color','#FB0000').html("数据库链接配置失败");	
					}
					else
					{
						$('#dbpwd_msg').css('color','#00FB00').html("数据库链接配置正确");	
					}
					if(msg.indexOf('3')>=0)
					{
						$('#dosubmit').attr("disabled",true);
						$('#dosubmit').addClass("nonext");
						$('#sysuser_msg').css('color','#FB0000').html("管理员帐号配置失败");
					}
					else
					{
						$('#sysuser_msg').css('color','#00FB00').html("管理员帐号配置正确");	
					}
					if(msg.indexOf('4')>=0)
					{
						$('#dosubmit').attr("disabled",true);
						$('#dosubmit').addClass("nonext");
						$('#syspwd_msg').css('color','#FB0000').html("管理员密码配置失败");
					}
					else
					{
						$('#syspwd_msg').css('color','#00FB00').html("管理员帐号配置正确");	
					}
					if(msg.indexOf('1')< 0 && msg.indexOf('2')< 0 && msg.indexOf('3')< 0 && msg.indexOf('4')< 0)
					{
						$('#dosubmit').attr("disabled",false);
						$('#dosubmit').removeAttr("disabled");				
						$('#dosubmit').removeClass("nonext");
					}
				},
				error:function(){
					$('#dbname_msg').css('color','#FB0000').html("数据库名称配置失败");
					$('#dbpwd_msg').css('color','#FB0000').html("数据库链接配置失败");
					$('#sysuser_msg').css('color','#FB0000').html("管理员帐号配置失败");
					$('#syspwd_msg').css('color','#FB0000').html("管理员密码配置失败");				
				}
			});
		}
	</script>
</html>